<template>
	<view>
		<uni-nav-bar :fixed="true" left-icon="back" color="#156DAC" @clickLeft="pageback">
			<view class="header-icon-text-panel">
				<text class="title">评价查询</text>
				<view style="margin-left: 10upx;" @click="showDrawer">
					<uni-icons type="search" size="16" color="#156DAC"></uni-icons>
				</view>
			</view>
		</uni-nav-bar>
		<view class="content padding">
			<view class="page-content-list">
				<block v-for="(value, index) in listData" :key="index">
					<view class="content-list-cell"  @click="goDetail(value)">
						<view class="order-item">
							<view class="order-item-content">
								<view class="order-content-row">
									<view class="label">项目部</view><view class="value" style="color: #299AEB;">{{value.departmentName}}</view>
								</view>
								<view class="order-content-row">
									<view class="label">发布人</view><view class="value">{{value.publisherName || '- -'}}</view>
								</view>
								<view class="order-content-row">
									<view class="label">负责人</view><view class="value">{{value.responsibleName || '- -'}}</view>
								</view>
								<view class="order-content-row">
									<view class="label">类型</view><view class="value">{{value.type===null?'--':value.type==='e005_01'?'报警':value.type==='e005_02'?'运维':'--'}}</view>
								</view>
								<view class="order-content-row">
									<view class="label">对运维结果评价</view>
									<uni-rate class="form-input no-border flex-start-center" disabled="true"  :size="18" :value="value.overallEvaluation"/>
								</view>
								<view class="order-content-row">
									<view class="label">对运维工程师评价</view>
									<uni-rate class="form-input no-border flex-start-center" disabled="true" :size="18" :value="value.disposalPersonnelEvaluation"/>
								</view>
								<view class="order-content-row">
									<view class="label">客户评价内容</view><view class="value">{{value.contentDescription || '- -'}}</view>
								</view>
								<!-- <view class="order-content-row">
									<view class="label">操作</view>
									<view class="value">
										<button class="order-btn">评价</button>
									</view>
								</view> -->
							</view>
						</view>
					</view>
				</block>
			</view>
			<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
		</view>
		
		<uniDrawer ref="draw" :mask="true" mode='right' :width="250">
			<view style="height: 90upx;">&nbsp;</view>
			<view class="draw-panel">
				<view class="drawer-form">
					<view class="drawer-form-item">
						<view class="drawer-label"><text>开始时间</text></view>
						<view class="drawer-content">
							<TimeSelector
								ref="stime"
								class="ipt-ctl"
							    showType="date"
								@btnConfirm="(e)=>dateChange(e,'startTime')" 
							>
							    <text v-if="query.startTime">{{query.startTime}}</text>
								<text v-else style="color: grey;">请选择开始时间</text>
							</TimeSelector>
						</view>
					</view>
					<view class="drawer-form-item">
						<view class="drawer-label"><text>结束时间</text></view>
						<view class="drawer-content">
							<TimeSelector
								ref="etime"
								class="ipt-ctl"
							    showType="date"
								@btnConfirm="(e)=>dateChange(e,'endTime')" 
							>
							    <text v-if="query.endTime">{{query.endTime}}</text>
								<text v-else style="color: grey;">请选择结束时间</text>
							</TimeSelector>
						</view>
					</view>
					<view class="drawer-form-item">
						<view class="drawer-label"><text>项目部</text></view>
						<view class="drawer-content">
							<lb-picker v-model="query.departmentId" :list="chooseProjectDepartments" :props="pickerDeptProps" @confirm="(e)=>pickerSelectConfim2('department',e)">
								<view class="lb-picker-placeholder-panel">
									<text v-if="query.departmentName" class="lb-picker-text">{{query.departmentName}}</text>
									<text v-else class="lb-picker-placeholder">请选择项目部</text>
								</view>
							</lb-picker>
						</view>
					</view>
					<view class="drawer-form-item">
						<view class="drawer-label"><text>发布人</text></view>
						<view class="drawer-content">
							<lb-picker v-model="query.responsibleId" :list="chooseUserList" :props="pickerUserProps" @confirm="(e)=>pickerSelectConfim('responsible',e)">
								<view class="lb-picker-placeholder-panel">
									<text v-if="query.responsibleName" class="lb-picker-text">{{query.responsibleName}}</text>
									<text v-else class="lb-picker-placeholder">请选择发布人</text>
								</view>
							</lb-picker>
						</view>
					</view>
				</view>
				
				<view class="operation-panel">
					<view class="item-card">
						<view class="card-title">
							<uni-icons class="icon left" type="gear" size="20" color="#156dac"></uni-icons>
							<text class="content">类型</text>
							<uni-icons class="icon right" type="arrowdown" size="16" color="#666"></uni-icons>
						</view>
						<view class="operation-panel flex" style="padding: 20upx 0 0  0;">
							<view 
								v-for="(item,index) in dataTypes" 
								class="item-btn mini auto" 
								:class="query.dataTypes === (item.code)?'':'white'" 
								@click="pickerConfim('dataType',item)" 
								:key="index"
							>
								<text>{{item.codeName}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="bottom-panel">
					<!-- <view class="item-btn green lp"><text>重置</text></view> -->
					<view class="item-btn lp" @click="handleQuery"><text>确定</text></view>
				</view>
			</view>
		</uniDrawer>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import uniIcons from "@/components/uni-icons/uni-icons.vue"
	import uniDrawer from "@/components/uni-drawer/uni-drawer.vue"
	import tkiTree from "@/components/tki-tree/tki-tree.vue"
	import LbPicker from '@/components/lb-picker'
	import TimeSelector from '@/components/wing-time-selector/wing-time-selector.vue';
	import {getDict} from '@/common/dict.js'
	import {parseTime} from '@/common/util.js'
	
	const listQuery = '/business/evaluation/pageEvaluation'
	const getProjectDepartmentUrl = '/base/department/ListProjectDepartment'
	const getUser = '/system/user/getProjectPersonnel'
	export default {
		components:{
			TimeSelector,
			uniIcons,
			uniLoadMore,
			uniDrawer,
			LbPicker,
			tkiTree
		},
		data() {
			return {
				reload: false,
				listData: [],
				last_id: '',
				status: 'loading',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				pickerUserProps: {
					label: 'realName',
					value: 'id',
				},
				pickerDeptProps: {
					label: 'name',
					value: 'id',
				},
				query: {
					total: 0,
					page: 1,
					limit: 10,
					departmentId: '',
					departmentName: '',
					startTime: '',
					endTime: '',
					dataType: '',
					responsibleId: '',
					responsibleName: '',
				},
				// 待选人
				chooseUserList: [],
				// 项目部
				chooseProjectDepartments: [],
				// 字典
				dataTypes: [],
			}
		},
		onLoad() {
			
			// 字典
			this.dataTypes = [{code:'',codeName:'全部'},...getDict('e005')]
			
			// 默认
			const beforeTime = new Date().getTime() - 1000*60*60*24*7
			const time = parseTime(new Date(),'{y}-{m}-{d}')
			const before = parseTime(new Date(beforeTime),'{y}-{m}-{d}')
			this.query.startTime = before
			this.query.endTime =  time
			
			this.getList();
			this.initUserList();
			this.initProjectDepts();
		},
		onPullDownRefresh() {
			this.last_id = '';
			this.listData =  []
			this.getList();
			setTimeout(()=>{
				uni.stopPullDownRefresh();
			},100)
		},
		onReachBottom() {
			this.status = 'more';
			this.query.page = this.query.page + 1
			this.getList(true);
		},
		methods: {
			handleQuery() {
				this.query.page = 1
				this.getList();
				this.$refs.draw.close()
			},
			pageback(){
				uni.navigateBack({
					delta: 1
				});
			},
			showPkPicker() {
				this.$refs.tkitree._show()
			},
			pkConfirm(e) {
				if(e.length > 0){
					const {areaid,areaname} = e[0]
					console.log(e)
					this.query.addressPId = areaid
					this.query.addressName = areaname
				}
			},
			showDrawer(){
				this.$refs.draw.open()
			},
			goDetail(item){
				const {id,type} = item
				const overallEvaluation = item.overallEvaluation || 0
				const disposalPersonnelEvaluation = item.disposalPersonnelEvaluation || 0
				const contentDescription = item.contentDescription || ''
				
				const pageType = 'detail'
				let c_url = `/pages/form/historyAlarmDetail/historyAlarmDetail`
				let param = ``
				if(type === 'e005_02'){
					c_url = '/pages/devopsDetail/devopsDetail'
					param = `&overallEvaluation=${overallEvaluation}&disposalPersonnelEvaluation=${disposalPersonnelEvaluation}&contentDescription=${contentDescription}`
				}
				uni.navigateTo({
					url:c_url+`?type=${pageType}&id=${id}`+param
				})
			},
			pickerSelectConfim(key,e){
				const {item} = e
				const {id, realName} = item
				this.query[key+ 'Id'] = id
				this.query[key+'Name'] = realName
			},
			pickerSelectConfim2(key,e){
				const {item} = e
				const {id, name} = item
				this.query[key+ 'Id'] = id
				this.query[key+'Name'] = name
			},
			pickerConfim(key, item){
				const {code, codeName} = item
				this.query[key] = code
				this.query[key+'Name'] = codeName
			},
			dateChange(res,type){
				this.query[type] = res.key
			},
			handleAdd(){
				
			},
			getList(loadMore = false){
				this.status = 'loading';
				this.$api.request(listQuery,{
					method: 'get',
					data: this.query
				}).then(res=>{
					if(res.success) {
						const {list} = res.data
						const {records} = list
						if(records.length === 0 || list.total <= this.query.limit){
							this.status = ''
						}
						if(loadMore){
							this.listData = [...this.listData,...records]
						}else{
							this.listData  = records
						}
						this.last_id = this.listData[this.listData.length - 1];
						this.reload = false;
					}
				}).catch((e)=>{
					console.log(e)
				})
			},
			// 获取下拉框数据
			initProjectDepts() {
				this.$api.request(getProjectDepartmentUrl,{
					method: 'get',
				}).then(res=>{
					const projectDepartmentOptions = res.data.projectDepartments
					this.chooseProjectDepartments = [{id:'',name:'全部'},...projectDepartmentOptions]
					
				})
			},
			initUserList() {
				this.$api.request(getUser,{
					method: 'get',
				}).then(res=>{
					if(res.success){
						this.chooseUserList = [{id:'',realName:'全部'},...res.data.row]
					}
				}).catch(()=>{
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	.page-content-list{
		position: relative;
		width: 100%;
		display: flex;
		flex-direction: column;
		.content-list-cell{
			position: relative;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
		}
	}
	.order-item{
		width: 750upx;
		background: #fff;
		padding: 20upx;
		border-radius: 20upx;
		margin-bottom: 20upx;
		.order-item-content{
			margin-top: 30upx;
			.order-content-row{
				display: flex;
				align-items: flex-start;
				justify-content: space-between;
				font-size: 26upx;
				margin-bottom: 30upx;
				.order-btn{
					display: inline-block;
					background-color: #156dac;
					color: #fff;
					width: 95upx;
					height: 50upx;
					line-height: 50upx;
					text-align: center;
					font-size: 24upx;
					padding: 0;
					margin-left: 10upx;
				}
				.label{
					flex: 0 0 200upx;
					color: #5A5A5A;
					text-align: left;
					font-size: 26upx;
				}
				.value{
					flex: 1;
					color: #000;
					text-align: right;
					font-size: 26upx;
					&.text-left{
						text-align: left;
						padding-left: 20upx;
					}
				}
			}
			
		}
			
		.order-item-header{
			display: flex;
			align-items: center;
			.icon{
				margin-right: 10upx;
			}
			text{
				color: #333;
				font-size: 26upx;
				&.green{
					color:#2AD51D;
				}
			}
			
		}
	}
</style>
